package com.example.service.impl.ums;

import com.example.common.UUIDUtils;
import com.example.mapper.ums.UmsAdminRoleMapper;
import com.example.model.ums.UmsAdminRole;
import com.example.service.ums.UmsAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户与角色关联Service
 */
@Service
@Transactional
public class UmsAdminRoleServiceImpl implements UmsAdminRoleService {

    @Autowired
    private UmsAdminRoleMapper mapper;


    @Override
    public List<UmsAdminRole> findUmsAdminRolesByParam(UmsAdminRole umsAdminRole) {
        return mapper.findUmsAdminRolesByParam(umsAdminRole);
    }

    @Override
    public UmsAdminRole findUmsAdminRoleByParam(UmsAdminRole umsAdminRole) {
        return mapper.findUmsAdminRoleByParam(umsAdminRole);
    }

    @Override
    public int insert(UmsAdminRole umsAdminRole) {
        UmsAdminRole umsAdminRoleParam = new UmsAdminRole();
        umsAdminRoleParam.setUmsAdminId(umsAdminRole.getUmsAdminId());
        UmsAdminRole umsAdminRoleByParam = mapper.findUmsAdminRoleByParam(umsAdminRoleParam);
        if(null != umsAdminRoleByParam){
            mapper.deleteByUmsAdminId(umsAdminRole);
        }
        umsAdminRole.setId(UUIDUtils.getId());
        return mapper.insert(umsAdminRole);
    }
}
